// pages/coupon/coupon.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    couponArr: [{
        CouponName: 'weianl红包',
        CouponTypeName: '满30元可用',
        CouponMoney: 5,
        HasItBeenClaimed: false,
      },
      {
        CouponName: 'weianl红包',
        CouponTypeName: '满100元可用',
        CouponMoney: 20,
        HasItBeenClaimed: false,
      },
      {
        CouponName: 'weianl红包',
        CouponTypeName: '满5000元可用',
        CouponMoney: 500,
        HasItBeenClaimed: false,
      },
      {
        CouponName: 'weianl红包',
        CouponTypeName: '满10000元可用',
        CouponMoney: 1000,
        HasItBeenClaimed: true,
      }
    ],
    topImages: 'http://m.qpic.cn/psc?/V14ZaBeY40XWC8/zkoezU7GGNbZGOF.DPhgQVgKh0Fw63ZhFQsd0hetQ8T6CBTPzbnz3dz1WfeDXiG6wY3NwfQcy1Y7Ry49HK1QdM9SKG1QzVXMBdXM0bH80fc!/b&bo=nQLyAJ0C8gADCSw!&rf=viewer_4',
    couponLeftImages: 'http://m.qpic.cn/psc?/V14ZaBeY40XWC8/zkoezU7GGNbZGOF.DPhgQXDCLspq1L1upRR.ZiRnZuFvq1XezxpUwmIc4ky9cr0DEpxn.YXOFA15Y03Wwkk2zJSBTVERFZsf3KTl5vSZorE!/b&bo=lgCWAJYAlgADCSw!&rf=viewer_4',
    closeBtnImages: 'http://m.qpic.cn/psc?/V14ZaBeY40XWC8/zkoezU7GGNbZGOF.DPhgQZjV2a5npNMM5D47K1jMLBHO3ccXXkEwsTHa*69Gi8pCGkdmz4imEISAR0fRbZj7*malDMMANN7ZzH8oI6XDWDk!/b&bo=QABAAEAAQAADCSw!&rf=viewer_4',
    // 是否显示优惠劵弹窗
    isShowCouponPopUp: true
  },

  //阻止弹出层滑动事件，空函数，不做任何处理
  onPreventTouchMove: function () {
    return false;
  },
  //打开优惠劵弹窗
  openTheCouponPopUp: function () {
    var that = this;
    setTimeout(() => {
      // 先开启优惠劵弹窗
      that.setData({
        isShowCouponPopUp: true
      })
      // 设置优惠劵弹窗打开动画
      var animation = wx.createAnimation({
        duration: 600,
        timingFunction: 'ease',
      })
      that.animation = animation;
      animation.scale(1).step();
      that.setData({
        animationData: animation.export()
      })
    }, 1000)
  },
  //关闭优惠劵弹窗
  closeTheCouponPopUp: function () {
    // 设置优惠劵弹窗关闭动画
    var animation = wx.createAnimation({
      duration: 300,
      timingFunction: 'ease',
    })
    this.animation = animation;
    animation.scale(0).step();
    this.setData({
      animationData: animation.export(),
    })
    //执行完动画后再关闭
    setTimeout(() => {
      this.setData({
        isShowCouponPopUp: false
      })
    }, 200)
  },
  //领取单个优惠劵
  getCoupons: function (e) {
    // console.log(e.currentTarget.dataset.index)
    var index = e.currentTarget.dataset.index;
    var couponArr = this.data.couponArr;
    couponArr[index].HasItBeenClaimed = true;
    this.setData({
      couponArr: couponArr
    })
  },
  //已领取优惠劵
  alreadyReceived: function () {
    wx.showToast({
      title: '已领取，可在卡包查看',
      icon: 'none'
    })
  },
  //领取全部优惠劵
  getAllCoupons: function () {
    var couponArr = this.data.couponArr;
    couponArr.forEach((item) => {
      item.HasItBeenClaimed = true;
    })
    this.setData({
      couponArr: couponArr
    })
    wx.showToast({
      title: '领取成功，已放入卡包',
      icon: 'none'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
})

